const clustersData = require("../test/0920/clusters.json");
const zhongjianzhi = require("../test/0920/zhongjian.json");
const fs = require("fs-extra");
const path = require("path");
// debugger
let cu = clustersData[0].map((e, i) => {
  e.index = i;
  return e;
});
let distances = [];
for (let i = 0; i < cu.length; i++) {
  let arr = [];
  for (let j = 0; j < cu.length; j++) {
    arr.push(null)
  }
  distances.push(arr);
}
for (let i = 0; i < cu.length; i++) {
  let line1 = cu[i];
  // let sline1 = JSON.stringify(line1);
  for (let j = 0; j < cu.length && j != i; j++) {
    if (distances[i][j]) {
      continue;
    }
    let lineEq = (l1, l2) => {
      return l1.start.x == l2.start.x
        && l1.start.y == l2.start.y
        && l1.end.x == l2.end.x
        && l1.end.y == l2.end.y
    }
    let line2 = cu[j];
    // let sline2 = JSON.stringify(line2);
    let record = zhongjianzhi.find(e => {
      if (lineEq(e.line1, line1) && lineEq(e.line2, line2)) {
        // debugger
        return true
      }
      if (lineEq(e.line1, line2) && lineEq(e.line2, line1)) {
        // debugger
        return true
      }
      // debugger
    });
    if (record) {
      let dist = {
        angu: record.angu,
        parr: record.parr,
        perp: record.perp,
        total: record.total
      }
      distances[i][j] = dist;
      distances[j][i] = dist;
    }


    // debugger
  }
}
fs.writeFile(path.join(__dirname,"../test/0920/shiyanjieguo.json"),JSON.stringify({
  lines:cu,
  distances
})).then(_=>{
  debugger
})
// debugger